﻿using com.iot.core.data.entity;

using System.Linq.Dynamic.Core;
using Microsoft.EntityFrameworkCore;
using com.iot.core.manager.auth;

namespace com.iot.core.data.service
{
    public class HtUserDeptService : BaseService<HtUserDept>, IHtUserDeptService
    {
        public async Task<List<HtDeptBaseDto>> GetDeptsAsync(long uid)
        {
            var DB = BaseMapper.DB;
            var l =  await DB.Set<HtUserDept>()
                .Where(a => a.HtuserId.Equals(uid) && a.State == "启用")
              .Join(
                    DB.Set<HtDept>(),
                    a => new { HtdeptId = a.HtdeptId, BDeleted = false, BState = "启用" },
                    b => new { HtdeptId = b.Id, BDeleted = b.Deleted, BState = b.State },
                    (a, b) => new HtDeptBaseDto { Id = b.Id, Name = b.Name, HtplatId = b.HtplatId, Pid = b.Pid }
                    )
              .ToListAsync();
            return  l;

        }
    }
}
